package arrAndstr;

/*
    167. 两数之和 II - 输入有序数组
 */
public class T167 {

    public static void main(String[] args) {
        int[] numbers = new int[]{-3,3,4,90};
        int target = 0;

        for (int i : twoSum(numbers, target)) {
            System.out.print(i + " ");
        }
    }


    public static int[] twoSum(int[] numbers, int target) {
        // 左边由于加，右边用于减
        int leftIndex = 0;
        int rightIndex = numbers.length - 1;

        while(leftIndex < rightIndex) {
            int tempValue = numbers[leftIndex] + numbers[rightIndex];
            if(tempValue < target) {
                leftIndex++;
            } else if(tempValue > target) {
                rightIndex--;
            } else {
                return new int[]{leftIndex+1, rightIndex+1};
            }
        }
        return new int[]{0,0};
    }


}
